#!/bin/bash

source /home/shell/util.sh


# 安装函数
function install () {
    if [ -d "/usr/local/src/openssl" ]; then
        git -C /usr/local/src/openssl pull
    else
        git clone https://hub.fastgit.org/openssl/openssl.git /usr/local/src/openssl
    fi
    
    while [ true ]; do
        printInfo "版本列表"
        git -C /usr/local/src/openssl branch -a|grep -Po "remotes/origin/.*"|grep -v HEAD|perl -pe "s/remotes\/origin\/(.*)/\1/g"
        read -p "请选择版本：" version
        if [[ -z "${version}" ]]; then
            printFail "请输入版本"
        else
            break;
        fi
    done
    git -C /usr/local/src/openssl checkout -b ${version} origin/${version}
    cd /usr/local/src/openssl
    ./Configure --prefix=/usr --openssldir=/usr/lib/ssl '-Wl,--enable-new-dtags,-rpath,$(LIBRPATH)'
    make && make install
    rm -rf /usr/local/src/openssl
}

# 配置函数
function config(){
    printInfo "==========================openssl=========================="
    printInfo "`openssl version -a`"
    printInfo "==========================openssl=========================="
}

# 运行安装和配置
install && config